using UnityEngine;

public class EnemyPhysicsCheck : PhysicsCheck {
    
    
    [Header("追逐检测")]
    public Transform chaseCheckPoint;
    public float chaseCheckLength;
    public LayerMask chaseLayer;
    public bool isCheckChase;
    public Transform chaseTarget;//目标
    [Header("攻击检测")]
    public Transform attackCheckPoint;
    public float attackCheckRadius;
    public LayerMask attackLayer;
    public bool isCheckAttack;
    public Transform attackTarget;//目标

    public override void Check(){
        base.Check();
        // 发射射线并获取击中信息
        RaycastHit2D hit = Physics2D.Raycast(chaseCheckPoint.position, Vector3.right * transform.localScale.x, chaseCheckLength, chaseLayer);

        // 检查是否击中了某个对象
        if (hit.collider != null)
        {
            isCheckChase = true;
            // 获取击中的对象的信息
            chaseTarget = hit.collider.gameObject.transform;
        }else{
            isCheckChase = false;
            chaseTarget = null;
        }

        Collider2D attackHit = Physics2D.OverlapCircle(attackCheckPoint.position, attackCheckRadius, attackLayer);
        // 检查是否击中了某个对象
        if (attackHit != null)
        {
            isCheckAttack = true;
            // 获取击中的对象的信息
            attackTarget = attackHit.gameObject.transform;
        }else{
            isCheckAttack = false;
            attackTarget = null;
        }
    }

    public override void OnDrawGizmos()
    {
        base.OnDrawGizmos();
        Gizmos.DrawLine(chaseCheckPoint.position, chaseCheckPoint.position + Vector3.right * transform.localScale.x * chaseCheckLength);
        Gizmos.DrawWireSphere((Vector2)attackCheckPoint.position, attackCheckRadius);
    }
}